package com.spring.ldap.model;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
import com.sun.org.apache.xml.internal.security.utils.Base64;

public class LDAPUser {

	private String cn;
	private String sn;
	private String pwd;
	private String mail;
	private String tel;

	public LDAPUser(String cn, String sn, String pwd, String mail, String tel) {
		this.cn = cn;
		this.sn = sn;
		this.pwd = pwd;
		this.mail = mail;
		this.tel = tel;
	}

	public LDAPUser(String cn, String sn) {
		this.cn = cn;
		this.sn = sn;
	}

	public LDAPUser(String cn) {
		this.cn = cn;
		this.sn = "";
	}
	
	public LDAPUser() {
	}

	public String getCn() {
		return cn;
	}

	public void setCn(String cn) {
		this.cn = cn;
	}

	public String getSn() {
		return sn;
	}

	public void setSn(String sn) {
		this.sn = sn;
	}

	public String getPwd() {
		return this.pwd;

	}

	public void setPwd(String pwd) {

		MessageDigest sha;
		try {
			sha = MessageDigest.getInstance("SHA-1");
			sha.reset();
			sha.update(pwd.getBytes());
			byte[] digest = sha.digest();
			String pass = new String(Base64.encode(digest));
			pass = "{SHA}" + pass;
			this.pwd = pass;
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public boolean verif() {
		boolean b;
		if (pwd.isEmpty() || sn.isEmpty() || cn.isEmpty() || mail.isEmpty() || tel.isEmpty())
			b = false;
		else {
			b = true;
		}
		return b;
	}

}
